-
-
Notifications
You must be signed in to change notification settings - Fork 362
fix(MultiSelectGeneric): update value when bind-Value changed #6505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideEnhance MultiSelectGeneric to react to bind-Value updates by implementing IModelEqualityComparer, introducing customizable equality parameters, and cleaning up obsolete placeholder logic. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ArgoZhang - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/BootstrapBlazor/Components/SelectGeneric/MultiSelectGeneric.razor.cs:15` </location>
<code_context>
/// </summary>
[ExcludeFromCodeCoverage]
-public partial class MultiSelectGeneric<TValue>
+public partial class MultiSelectGeneric<TValue> : IModelEqualityComparer<TValue>
{
private List<SelectedItem<TValue>> SelectedItems { get; } = [];
</code_context>
<issue_to_address>
Consider removing the interface and attribute-based comparison logic in favor of a single comparer delegate parameter with a sensible default.
```suggestion
// 1. Remove the IModelEqualityComparer<TValue> implementation, the explicit interface, CustomKeyAttribute,
// and the Equals(x,y) override.
// 2. Expose a single comparer parameter (Func<TValue, TValue, bool>) with a default to EqualityComparer<TValue>.Default.
//
// Before:
public partial class MultiSelectGeneric<TValue> : IModelEqualityComparer<TValue>
{
[Parameter]
public Func<TValue, TValue, bool>? ValueEqualityComparer { get; set; }
Func<TValue, TValue, bool>? IModelEqualityComparer<TValue>.ModelEqualityComparer
{
get => ValueEqualityComparer;
set => ValueEqualityComparer = value;
}
[Parameter]
public Type? CustomKeyAttribute { get; set; } = typeof(KeyAttribute);
public bool Equals(TValue? x, TValue? y) => this.Equals<TValue>(x, y);
// …lots of extra indirection…
}
// After:
public partial class MultiSelectGeneric<TValue>
{
/// <summary>
/// Compare two TValue instances. Defaults to default equality.
/// </summary>
[Parameter]
public Func<TValue, TValue, bool> ValueComparer { get; set; }
= (x, y) => EqualityComparer<TValue>.Default.Equals(x, y);
// In your selection logic:
protected override void OnParametersSet()
{
SelectedItems.Clear();
if (Value != null)
{
foreach (var v in Value)
{
// no more CustomKeyAttribute or interface indirection
var item = Rows.Find(i => ValueComparer(i.Value!, v!));
if (item != null)
{
SelectedItems.Add(item);
}
}
}
}
}
```
This preserves all functionality, removes the extra interface and attribute-type plumbing, and uses a single, straightforward comparer delegate.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
src/BootstrapBlazor/Components/SelectGeneric/MultiSelectGeneric.razor.cs
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6505 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 714 714
Lines 31387 31387
Branches 4431 4431
=========================================
Hits 31387 31387
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #6504
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Fix selected items not updating when the bound Value changes in MultiSelectGeneric by implementing a model equality comparer interface and exposing customization points for item comparison.
Bug Fixes:
Enhancements: